import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Anim')
export default class FingerAnimation extends Component {
    @property
    public scaleDirection: number = 1; // 1表示放大，-1表示缩小
    private scaleSpeed: number = 0.05; // 缩放速度
    private maxScale: number = 0.6; // 最大缩放比例
    private minScale: number = 0.4; // 最小缩放比例

    start() {
        // 开始动画
        this.animateFinger();
    }

    private animateFinger() {
        // 获取当前缩放值
        const currentScale = this.node.scale.clone(); // 克隆当前缩放值

        // 更新缩放
        currentScale.x += this.scaleSpeed * this.scaleDirection;
        currentScale.y += this.scaleSpeed * this.scaleDirection;

        // 检查缩放边界
        if (currentScale.x >= this.maxScale || currentScale.y >= this.maxScale) {
            this.scaleDirection = -1; // 反方向缩放
        } else if (currentScale.x <= this.minScale || currentScale.y <= this.minScale) {
            this.scaleDirection = 1; // 反方向放大
        }

        // 应用新的缩放值
        this.node.scale = currentScale;

        // 继续下一帧
        this.scheduleOnce(() => this.animateFinger(), 0);
    }
}